package com.star.controller.web;

import com.star.dto.ResponseData;
import com.star.util.InspectionTokenUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Classname MyInfo
 * @Author Star
 * @Date 2021/4/23 - 8:37
 * @Description
 */
@Controller
@RequestMapping("/myPage")
public class MyInfoController {
    /*我的主页*/
    @RequestMapping("/info")
    private String myInfo(String token) {
        return "public/my/my";
    }

    /*登录*/
    @RequestMapping("/login")
    private String myLogin(String token) {
        //查看返回值是否匹配
        ResponseData inspection = InspectionTokenUtils.inspectionForm(token);
        //判断是否是否有token 证明已经登录了 进行跳转404
        if (inspection.getCode() == ResponseData.ok().getCode()) {
            return "public/404";
        } else {
            //有token
            return "public/my/mylogin";
        }
    }

    /*注册 */
    @RequestMapping("/myregister")
    private String myRegister(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //查看返回值是否匹配
        ResponseData inspection = InspectionTokenUtils.inspection(request, response);
        //判断是否是否有token 证明已经登录了 进行跳转404
        if (inspection.getCode() == ResponseData.ok().getCode()) {
            //有token
            return "public/404";
        } else {
            //证明没有登录 进行注册等操作
            return "public/my/myregister";
        }

    }

    /*用户信息*/
    @RequestMapping("/myInfo")
    private String holdUpInfo(String token) {
        //查看返回值是否匹配
        ResponseData inspection = InspectionTokenUtils.inspectionForm(token);
        //判断是否是否有token 证明已经登录了 进行跳转404
        if (inspection.getCode() == ResponseData.ok().getCode()) {
            //有token 查看用户信息
            return "holdUp/my/myInfo";
        } else {
            //证明没有登录 跳转登录页面
            return "public/my/myregister";
        }
    }
}


